package com.sunlands.deskmate.message.enums;

import com.sunlands.deskmate.message.handler.dispatcher.*;
import com.sunlands.deskmate.message.handler.dispatcher.impl.*;
import com.sunlands.deskmate.message.handler.receiver.*;
import com.sunlands.deskmate.message.handler.receiver.impl.AckMessageReceiver;
import com.sunlands.deskmate.message.handler.receiver.impl.DefaultMessageReceiver;
import com.sunlands.deskmate.message.handler.receiver.impl.HeartBeatMessageReceiver;
import com.sunlands.deskmate.message.handler.receiver.impl.PrivateMessageReceiver;

/**
 * Created by yanliu on 2019/4/17.
 */
public enum MessageType {

    HEART_BEAT("800", "切换前后台运行", HeartBeatMessageReceiver.class, null),

    PRIVATE_CHAT("100", "私聊", PrivateMessageReceiver.class, PrivateMessageDispatcher.class),
    ENTER_PRIVATE_CHAT("101", "进入私聊", DefaultMessageReceiver.class, PrivateMessageDispatcher.class),
    QUIT_PRIVATE_CHAT("102", "退出私聊", DefaultMessageReceiver.class, PrivateMessageDispatcher.class),
    SHARE_GROUP_TO_PRIVATE("103", "分享群到私聊", DefaultMessageReceiver.class, PrivateMessageDispatcher.class),
    SHARE_ROOM_TO_PRIVATE("104", "分享room到私聊", DefaultMessageReceiver.class, PrivateMessageDispatcher.class),
    SHARE_DIARY_TO_PRIVATE("105", "分享某个日记到私聊", DefaultMessageReceiver.class, PrivateMessageDispatcher.class),
    SHARE_DIARY_COMMENT_TO_PRIVATE("116", "分享某个日记评论到私聊", DefaultMessageReceiver.class, PrivateMessageDispatcher.class),

    GROUP_CHAT("200", "群聊", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    ENTER_GROUP("201", "进入群聊", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    QUIT_GROUP("202", "退出群聊", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    SHARE_GROUP_TO_GROUP("203", "分享群到群聊", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    SHARE_DIARY_TO_GROUP("205", "分享某个日记到群聊", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    SHARE_ROOM_TO_GROUP("204", "分享房间到群聊", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    group_user_join("211", "加入群", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    group_user_exit("212", "退出群", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    group_create("213", "创建群--群消息-创建成功", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    group_join("214", "创建群--群消息-讨论小组邀请进群", DefaultMessageReceiver.class, GroupMessageDispatcher.class),
    SHARE_DIARY_COMMENT_TO_GROUP("216", "分享某个日记评论到群聊", DefaultMessageReceiver.class, GroupMessageDispatcher.class),

    ROOM_CHAT("300", "室聊", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    ENTER_ROOM("301", "进入室聊", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    QUIT_ROOM("302", "退出室聊", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    SHARE_GROUP_TO_ROOM("303", "分享群到room聊", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    SHARE_ROOM_TO_ROOM("304", "分享room到其它room聊", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    SHARE_DIARY_TO_ROOM("305", "分享某个日记到room聊", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    APPLY_PUBLISH("306", "申请上麦", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    CANCEL_APPLY_PUBLISH("307", "取消申请上麦", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    AgreeApplyPublish("308", "房主同意上麦", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    QuitPublish("309", "下麦", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    OperateAllMic("310", "全员禁麦操作", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    OWN_MIC_OPERATION("311", "自己麦克操作", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    HostChange("312", "切换房主", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    KICKING("313", "踢人", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    CLOSE_ROOM("314", "关闭房间", DefaultMessageReceiver.class, LiveRoomCloseDispatcher.class),
    FORCE_ROOM_CLOSURE("315", "强制关闭房间", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    SHARE_DIARY_COMMENT_TO_ROOM("316", "分享某个日记评论到room聊", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    HEART_MISSING_CLOSE_ROOM("317", "心跳丢失关闭房间", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    ILLEGAL_KICKING("323", "违规踢人", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),

    VIP_TIME_SWITCH("350", "切换时长", DefaultMessageReceiver.class, OnePersonMessageDispatcher.class),
    VIP_TIME_USE_UP("351", "全部时长用尽", DefaultMessageReceiver.class, OnePersonMessageDispatcher.class),
    STUDY_DAY_AND_VIP_TIME_USE_UP("352", "全部时长用尽-从开放日时长结束", DefaultMessageReceiver.class, OnePersonMessageDispatcher.class),

    NO_AUTH("401", "没有权限", DefaultMessageReceiver.class, null),

    TIME_LEARN_ROOM_TEXT("400", "计时自习室-文本消息", DefaultMessageReceiver.class, TimeLearnRoomMessageDispatcher.class),
    TIME_LEARN_ROOM_ENTER("411", "计时自习室-进入消息", DefaultMessageReceiver.class, TimeLearnRoomMessageDispatcher.class),
    TIME_LEARN_ROOM_EXIT("412", "计时自习室-离开消息", DefaultMessageReceiver.class, TimeLearnRoomMessageDispatcher.class),
    TIME_LEARN_ROOM_TAKE_SEAT("421", "计时自习室-入座", DefaultMessageReceiver.class, TimeLearnRoomMessageDispatcher.class),
    TIME_LEARN_ROOM_SIT_UP("422", "计时自习室-离开座位", DefaultMessageReceiver.class, TimeLearnRoomMessageDispatcher.class),

    ACK("501", "ACK消息", AckMessageReceiver.class, null),

    USER_ONLINE("601", "用户-用户上线", DefaultMessageReceiver.class, OnePersonMessageDispatcher.class),
    USER_OFFLINE("602", "用户-用户下线", DefaultMessageReceiver.class, OnePersonMessageDispatcher.class),
    TIME_LEARN_ROOM_TAKE_SEAT_NOTICE("603", "计时自习室-入座", DefaultMessageReceiver.class, OnePersonMessageDispatcher.class),
    TIME_LEARN_ROOM_SIT_UP_NOTICE("604", "计时自习室-离开座位", DefaultMessageReceiver.class, OnePersonMessageDispatcher.class),


    DYNAMIC_MESSAGE("700", "个人（你或TA）相关动态", DefaultMessageReceiver.class, DynamicMessageDispatcher.class),
    DYNAMIC_CREATE_ROOM("750", "动态创建房间", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    DYNAMIC_CLOSE_ROOM("751", "动态关闭房间", DefaultMessageReceiver.class, LiveRoomMessageDispatcher.class),
    XIAOBIRD("760", "小书童相关动态", DefaultMessageReceiver.class, DynamicMessageDispatcher.class),
    INTERACTIVE_NOTICE("798", "互动通知", DefaultMessageReceiver.class, DynamicMessageDispatcher.class),
    PARTNER_INVITATION("799", "结伴邀请", DefaultMessageReceiver.class, DynamicMessageDispatcher.class),
    ERROR_FORMAT("9000", "错误消息格式", DefaultMessageReceiver.class, null),
    SPEAK_LIMIT("9001", "经系统检测，你已多次发表不利言论，请谨慎发言！", PrivateMessageReceiver.class, OnePersonSocketMessageDispatcher.class),
    BLACK_LIST_LIMIT("9002", "您已经被对方拉入黑名单，消息被拒收", PrivateMessageReceiver.class, OnePersonSocketMessageDispatcher.class),
    NOTICE_EVENT("999", "通知客户端拉去离线消息", DefaultMessageReceiver.class, OnePersonSocketMessageDispatcher.class),
    ;

    private String type;
    private String name;
    private Class<Receiver> receiver;
    private Class<Dispatcher> dispatcher;

    MessageType(String type, String name, Class receiver, Class dispatcher) {
        this.type = type;
        this.name = name;
        this.receiver = receiver;
        this.dispatcher = dispatcher;
    }

    public String getType() {
        return type;
    }


    public String getName() {
        return name;
    }

    public Class<Receiver> getReceiver() {
        return receiver;
    }

    public Class<Dispatcher> getDispatcher() {
        return dispatcher;
    }

    public static MessageType of(String type) {
        for (MessageType mt : MessageType.values()) {
            if (mt.getType().equals(type)) {
                return mt;
            }
        }
        throw new NullPointerException("没有找到对应的消息类型 type = " + type);
    }
}
